/**
 * 组件代码
 */
Vue.component('comSougnCheck', {
    name: 'comSougnCheck',
    props: ['config', 'data'],
    data: function () {
        return {
            checkValue: [],
            allData: []
        }
    },
    computed: {
        myConfig: function () {
            var data = {};
            for (var item of this.config) {
                data[item.id] = item.value;
            }
            return data;
        },
    },
    watch: {
        data: function (oldValue, newValue) {
            this.dataChange();
        },
        checkValue: function (oldValue, newValue) {
            if(this.myConfig.output.trim() == ''){
                return ;
            }else {
                window.setValue(this.myConfig.output, newValue);
            }

        }
    },
    mounted() {
        this.dataChange();
    },
    methods: {
        dataChange: function () {
            var data = window.getValue(this.myConfig.data).reduce(function (a, b) {
                return a.concat(b)
            });
            ;
            var title = window.getValue(this.myConfig.title).reduce(function (a, b) {
                return a.concat(b)
            });
            var allData = [];
            for (var item in data) {
                allData.push({
                    value: data[item],
                    title: title[item]
                })
            }
            this.allData = allData;
        }
    },
    template: `<div :style="myConfig"><label  v-for="item of allData"><input :name="item.value" :value="item.value" type="checkbox" v-model="checkValue"/>{{item.title}}</label></div>`,
});
/**
 * 配置项
 * @type {{name: string, id: string, type: string, value: string}[]}
 */
var comSougnCheckConfig = [{
    name: "数据",
    type: "data",
    value: "",
    id: "data"
}, {
    name: "标题",
    type: "data",
    value: "",
    id: "title"
}, {
    name: "输出值",
    type: "data",
    value: "",
    id: "output"
}]
